package com.ls.demo.http.service.impl;

import com.google.gson.Gson;
import com.ls.demo.bean.Command;
import com.ls.demo.bean.RoomBoxInfo;
import com.ls.demo.bean.UncheckCommand;
import com.ls.demo.enums.MessageAttrEnum;
import com.ls.demo.http.service.DownloadService;
import lombok.extern.java.Log;
import org.springframework.stereotype.Service;

import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author liShan
 * @date 2019/9/4 22:54
 * @see MessageAttrEnum
 */
@Service("downloadUnlockServiceImpl_32")
@Log
public class DownloadUnlockServiceImpl implements DownloadService {

    @Override
    public String execute(String str, Command command) {
        Gson gson = new Gson();
        UncheckCommand c = gson.fromJson(str, UncheckCommand.class);
        log.info(c.toString());
        RoomBoxInfo boxInfo = c.getBoxInfo();
        c.assCommand(command);
        command.setDataList(Stream.of(Integer.toHexString(c.getLockType()),
                Integer.toHexString(c.getLock())).collect(Collectors.toList()));
        return boxInfo.getBoxId();
    }
}
